// INCLUDES --------------------------------------------------------------------
#include "Triangle.h"

// FUNCTIONS -------------------------------------------------------------------

/* GENERAL:
   d    -> destination
   s    -> source
   size -> array size (0,1 for single elements)

   t    -> arbitrary triangle
   r    -> arbitrary ray
*/

void TriangleClear(Triangle *t, ui32 size)
{
  GUARD_NULL("TriangleClear *t", t);
  
  // clamp range to at least one element
  CLAMP_LOW(size, 1); 

  /* clear triangle(s) to standard set:
     
     [A:0,0,0,1
      B:1,0,0,1
	    C:0,1,0,1],

     counterclockwise winding
  */

  // TODO: address performance penalty by overhead Vector4Clear() calls
  i32 i;
  for (i = 0; i < (i32)size; i++)
  {
    Vector4Clear(&t[i].T[0], 3); // set A,B,C to [0,0,0,1]
    t[i].B.x = t[i].C.y = 1.0f;  // set B:[1,0,0,1], C:[0,1,0,1]

    t[i].zNear = 0.0f;           // reset ray hit distance to 0
  }
};

// clone triangle src->dest
void TriangleCopy(Triangle *d, Triangle *s, ui32 size)
{
  // copy contents
  FillCopy(d, s, sizeof(Triangle), size);
};

// compute intersection
bool TriangleIntersect(Triangle *t, Ray *r, ui32 size)
{
  GUARD_NULL("TriangleIntersect *t", t, false);
  GUARD_NULL("TriangleIntersect *r", r, false);
  
  // clamp range to at least one element
  CLAMP_LOW(size, 1); 

  // TODO: add triangle intersection code.

  return false;
};
